//
//  BaseDetailViewController.m
//  Bus_iPhone
//
//  Created by antunnel on 12-7-2.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BaseDetailViewController.h"

@interface BaseDetailViewController ()

@end

@implementation BaseDetailViewController

@synthesize tableView=_tableView;

-(void)dealloc{

    [_tableView release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if (_tableView==nil) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
        _tableView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        [self.view addSubview:_tableView];
        _tableView.backgroundView=nil;
        _tableView.delegate=self;
        _tableView.dataSource=self;
    }
    /*
    UIImage *moreImg=[UIImage imageNamed:@"chat_bottom_down.png"];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(0.0f, 5.0f, 50.0f, 33.0f);
    [btn addTarget:self action:@selector(moreTool) forControlEvents:UIControlEventTouchUpInside];
    [btn setImage:moreImg forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:[btn autorelease]];*/
    
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)moreTool{

    UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:@"更多" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"短信分享" otherButtonTitles:@"邮件分享", nil];
    [sheet showFromTabBar:self.tabBarController.tabBar];
    [sheet release];
}

-(void)shearSMS{

    //shear to sms
}

-(void)collection{

    //do collection
}

#pragma mark -UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    return nil;
}

#pragma MARK - UIActionSheetDelegate

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex==0) {
        [self shearSMS];
    }else if (buttonIndex==1) {
        [self showEmailPicker];
    }else if (buttonIndex==2) {
        [self collection];
    }
}
#pragma mark -Email

// emlai 

-(void)showEmailPicker{
    
    @try {
        Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
        if (mailClass != nil)
        {
            // We must always check whether the current device is configured for sending emails
            if ([mailClass canSendMail])
            {
                [self displayComposerSheet];
            }
            else
            {
                [self launchMailAppOnDevice];
            }
        }
        else
        {
            [self launchMailAppOnDevice];
        }
    }
    @catch (NSException *exception) {
        
    }
    @finally {
        
    }
    
}


-(void)displayComposerSheet{
    
    
}

-(void)launchMailAppOnDevice{
    
    
}


- (void)mailComposeController:(MFMailComposeViewController*)controller 
		  didFinishWithResult:(MFMailComposeResult)result 
						error:(NSError*)error {	
	// Notifies users about errors associated with the interface
    
    
	NSString *msg;
	switch (result) {
		case MFMailComposeResultCancelled:
			msg = @"Canceled";
            
			[self dismissModalViewControllerAnimated:YES];
            
			return;
			break;
		case MFMailComposeResultSaved:
			msg = @"Undone, Incorrect serial number!";
			break;
		case MFMailComposeResultSent:
			msg = @"Send successfully";
			break;
		case MFMailComposeResultFailed:
			msg = @"Failed to send";
			break;
		default:
			msg = @"Failed to send";
			break;
	}
	// send and alert
	UIAlertView *basealert;
	basealert = [[UIAlertView alloc] initWithTitle:@"Message" message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok",nil];
	[basealert show];
	[self dismissModalViewControllerAnimated:YES];
	[msg release];
}

@end
